﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace GameAiLaTrieuPhu_Server
{
    public class Question
    {
        private string _Category;

        public string Category
        {
            get { return _Category; }
            set { _Category = value; }
        }

        private string _Content;

        public string Content
        {
            get { return _Content; }
            set { _Content = value; }
        }

        private string _Note;

        public string Note
        {
            get { return _Note; }
            set { _Note = value; }
        }

        private int _nAnswer;

        public int nAnswer
        {
            get { return _nAnswer; }
            set { _nAnswer = value; }
        }

        public List<Answer> listAnswers;

        // Constructor: 
        //      + Parameter: XmlNode QUESTION
        public Question(XmlNode nodeQuestion)
        {
            _Category = nodeQuestion.Attributes["Category"].Value;
            _Content = nodeQuestion.Attributes["Content"].Value;
            _Note = nodeQuestion.Attributes["Note"].Value;
            _nAnswer = nodeQuestion.ChildNodes.Count;
            listAnswers = new List<Answer>();
            for (int i = 0; i < nAnswer; i++)
            {
                XmlNode nodeAnswer = nodeQuestion.ChildNodes[i];
                Answer answer = new Answer(nodeAnswer);
                listAnswers.Add(answer);
            }
        }

        // Method isCorrect is used for compare Player's answer and System's answer
        //      + Parameter: string Player's answer
        //      + Return:   True if similarity
        //                  False if difference
        public bool isCorrect(string strPlayerAnswer)
        {
            for (int i = 0; i < nAnswer; i++)
            {
                if (strPlayerAnswer == listAnswers[i].Content)
                    return true;
            }

            return false;
        }
    }
}
